package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "申请单模块")
@RestController
@RequestMapping("/v1/application/")
public class ApplicationController {
    @Autowired
    ApplicationService applicationService;

    @GetMapping("select")
    @Operation(summary = "查询申请单")
    @ApiOperationSupport(order = 10)
    public JsonResult selectApplication(ApplicationQuery applicationQuery){
        log.debug("开始处理【查询申请单】的请求,参数:{}",applicationQuery);
        List<ApplicationVO> list = applicationService.selectApplication(applicationQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    @Operation(summary = "保存申请单")
    @ApiOperationSupport(order = 20)
    public JsonResult saveApplication(@Validated ApplicationSaveParam applicationSaveParam){
        log.debug("保存申请单:{}",applicationSaveParam);
        applicationService.saveApplication(applicationSaveParam);
        return JsonResult.ok();
    }
    @Operation(summary = "撤销申请单")
    @ApiOperationSupport(order = 30)
    @PostMapping("cancel/{id}")
    public JsonResult cancel(@PathVariable Long id) {
        log.debug("撤销申请单:{}", id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }
}
